package com.sise.wangzhan;

import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

/**
 * @Classname MyHealthCheckHandler
 * @Description TODO    实现健康检查处理器，将服务健康状态告诉服务器，一旦状态发送改变，重新向服务器注册
 * @Date 2020/3/19 11:30
 * @Created by wangzhan
 */
@Component
public class MyHealthCheckHandler implements HealthCheckHandler {

    @Autowired
    private MyHealthIndicator indicator;

    @Override
    public InstanceInfo.InstanceStatus getStatus(InstanceInfo.InstanceStatus instanceStatus) {
        Status status = indicator.health().getStatus();
        if (status.equals(Status.UP)){
            System.out.println("数据库正常连接！！！！！！");
            return InstanceInfo.InstanceStatus.UP;
        }else {
            System.out.println("数据库无法连接？？？？？？");
            return InstanceInfo.InstanceStatus.DOWN;
        }


    }
}
